#coding=utf-8
import unittest
from selenium import webdriver
from appium import webdriver
from time import sleep
from nav_plugin_op import nav_plugin_factory
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.support.ui import WebDriverWait
import os
from Public import BasePage
from Tool.usefulTools import userfulToolsFactory
from Public.BasePage import element_Oprate
from Public.BasePage import BasicAction
from Public import BaseConstant

#实例化基础数据
navOpenFactory = nav_plugin_factory()
userfulTool = userfulToolsFactory()
element_oprate_instance = element_Oprate()
basicAction = BasicAction()
IllegalReportt_Paramter_instances = BaseConstant.IllegalReportt_Paramter
# nav_name = "工作"
# plugin_name = "案件处置"
nav_name = ["导航栏工作",'xpath',"//android.widget.LinearLayout/android.widget.LinearLayout[2]/android.widget.FrameLayout/android.widget.RadioButton"]
plugin_name = ["插件列表-违建上报",'name','违建上报']
report_desc_name = "违建上报"
illegal_person_name = "小明"
illegal_tel_name = "12345678901"

class illegal_report_factory():

	def open_illegalreport_plug(self,driver,file_path):
		try:
			element_oprate_instance.element_click(nav_name,file_path)
			driver.swipe(400,1000,400,200,1200)
			sleep(2)
			element_oprate_instance.element_click(plugin_name,file_path)
			driver.implicitly_wait(15)
			element_oprate_instance.element_save_pic(file_path, 'open_illegalreport_successful')

		except WebDriverException,error:
			print error
			element_oprate_instance.element_save_pic(file_path, 'open_illegalreport_fail')
			raise

	def add_case(self,driver,file_path):
		try:
			element_oprate_instance.element_click(IllegalReportt_Paramter_instances.report_new_id, file_path)
			driver.implicitly_wait(15)
			element_oprate_instance.element_click(IllegalReportt_Paramter_instances.illegal_person_id, file_path)
			element_oprate_instance.element_send_keys(IllegalReportt_Paramter_instances.illegal_person_id,illegal_person_name.decode("utf-8"), file_path)
			element_oprate_instance.element_click(IllegalReportt_Paramter_instances.illegal_tel_id, file_path)
			element_oprate_instance.element_send_keys(IllegalReportt_Paramter_instances.illegal_tel_id,illegal_tel_name.decode("utf-8"), file_path)
			element_oprate_instance.element_click(IllegalReportt_Paramter_instances.location_desc_id, file_path)
			element_oprate_instance.element_click(IllegalReportt_Paramter_instances.location_confirm_name, file_path)
			driver.implicitly_wait(15)
			element_oprate_instance.element_click(IllegalReportt_Paramter_instances.confirm_btn_name, file_path)
			driver.implicitly_wait(15)
			element_oprate_instance.element_click(IllegalReportt_Paramter_instances.report_desc_id, file_path)
			element_oprate_instance.element_send_keys(IllegalReportt_Paramter_instances.report_desc_id,report_desc_name.decode("utf-8"), file_path)
			element_oprate_instance.element_click(IllegalReportt_Paramter_instances.media_view_id, file_path)
			element_oprate_instance.element_click(IllegalReportt_Paramter_instances.photoadd_id, file_path)
			sleep(2)
			element_oprate_instance.element_click(IllegalReportt_Paramter_instances.photo_xpath, file_path)
			element_oprate_instance.element_click(IllegalReportt_Paramter_instances.select_id, file_path)
			driver.implicitly_wait(15)
			element_oprate_instance.element_click(IllegalReportt_Paramter_instances.confirm_btn_name, file_path)
			driver.implicitly_wait(15)
			element_oprate_instance.element_click(IllegalReportt_Paramter_instances.confirm_btn_name, file_path)
			element_oprate_instance.element_save_pic(file_path, 'add_case_successful')

		except WebDriverException,error:
			print error
			element_oprate_instance.element_save_pic(file_path, 'add_case_fail')
			raise
			
if __name__ == '__main__':
	unittest.main()